//
//  HYUIScale.h
//  HyjrApp
//
//  Created by sgf on 2018/3/29.
//  Copyright © 2018年 Bank of Hangzhou Consumer Finance Co.,Ltd. All rights reserved.
//


//extern CGFloat scale_font(CGFloat fontsize);
//
////缩放高度（根据屏幕全宽）(以iphone6为标准尺寸)
//extern CGFloat scale_by_screen_width(CGFloat height);
//
////自定义尺寸进行高度缩放
//extern CGFloat scale_height(CGFloat height, CGFloat width, CGFloat realWidth);


//字体缩放（以iphone6为标准尺寸）
CGFloat scale_font(CGFloat fontsize)
{
    return scale_height(fontsize,375.f,SCREEN_WIDTH);
}

//缩放高度（根据屏幕全宽）(以iphone6为标准尺寸)
CGFloat scale_by_screen_width(CGFloat height)
{
    return scale_height(height,375.f,SCREEN_WIDTH);
}

//根据屏幕高度进行缩放
CGFloat scale_by_screen_height(CGFloat height)
{
    return scale_height(height,667.f,SCREEN_HEIGHT);
}

//自定义尺寸进行高度缩放
CGFloat scale_height(CGFloat height, CGFloat width, CGFloat realWidth)
{
    return (realWidth) / (width) * (height);
}



CGRect scale_rect(CGRect rect)
{
    return CGRectMake( scale_by_screen_width(rect.origin.x),
                      scale_by_screen_width(rect.origin.y),
                      scale_by_screen_width(rect.size.width),
                      scale_by_screen_width(rect.size.height)
                      );
    
}


CGSize scale_size(CGSize size)
{
    return CGSizeMake(
                      scale_by_screen_width(size.width),
                      scale_by_screen_width(size.height)
                      );
}



@implementation UIFont (Scale)

+ (UIFont *) scale_systemFontOfSize:(CGFloat)fontSize
{
    return [self systemFontOfSize:scale_font(fontSize)];
}

+ (UIFont *) scale_boldSystemFontOfSize:(CGFloat)fontSize
{
    return [self boldSystemFontOfSize:scale_font(fontSize)];
}

@end



@implementation MASConstraint(Scale)

- (MASConstraint * (^)(CGFloat offset))scale_offset
{
    return ^id(CGFloat offset){
        self.offset = scale_by_screen_width(offset);
        return self;
    };
}

- (MASConstraint * (^)(CGFloat var))scale_equalTo
{

    return ^id(CGFloat var)
    {
        CGFloat number = scale_by_screen_width(var);
        return self.equalTo( [NSNumber numberWithDouble:number] );
    };
}


- (MASConstraint * (^)(CGSize size))scale_equalToSize
{
    return ^id(CGSize var)
    {
        CGSize s = scale_size(var);
        return self.mas_equalTo( s );
    };
}


- (MASConstraint * (^)(CGFloat var))scale_equalTo_by_screen_heigh
{
    return ^id(CGFloat var)
    {
        CGFloat number = scale_by_screen_height(var);
        return self.equalTo( [NSNumber numberWithDouble:number] );
    };
}


- (MASConstraint * (^)(CGFloat var))scale_offset_by_screen_heigh
{
    return ^id(CGFloat offset){
        self.offset = scale_by_screen_height(offset);
        return self;
    };
}
@end
